<template>
  <BasicModal :show="show" title="入职" width="30%" :widthComfirm="true" @comfirm="comfirm" @closeModal="show = false">
    <template #content>
      <CommonForm :formList="formList" ref="formRef" labelWidth="100px"></CommonForm>
    </template>
  </BasicModal>
</template>

<script setup lang='ts'>
import { ref, watch } from "vue"
import type { Rule } from 'ant-design-vue/es/form';
import BasicModal from "./BasicModal.vue";
import CommonForm from "@/views/applicationDetails/CommonForm.vue";
import { message } from "ant-design-vue";
import {onBoardingProgress,
  selectCommonConfigDetail, selectUserByRole, selectCommonConfigFoChildren,
  secondInterview, getEntrySchoolInfo
} from "@/api/application-details/index.ts";


import { comStores } from '@/store/common/comStore';
const store = comStores()


const { userName } = store.userInFor

interface Options {
  label: string;
  value?: string | number
}
const props = defineProps(['param'])
const show = ref<boolean>(false);
const formList = ref([
  { label: "入职", name: "cascader", value: [], component: 'cascader', options: [] },
  { label: "导师", name: "entryTeacher", value: "", component: 'select', options: [] },
  { label: "备注", name: "remark", value: "", component: 'textarea' ,required:false},
])

watch(() => show.value, (val) => {
  if (val) {
    getOptions();

  }
})


const getOptions = async () => {
  const { resumeId } = store.currentResume;
  const teacher = await selectUserByRole("MENTOR") //导师
  const subject = await selectCommonConfigFoChildren({ type: 1 }) //科目
  let info = await getEntrySchoolInfo({ resumeId, type: 0 });
  if (info.data) {
    const { school, subject, grade } = info.data
    formList.value[0].value = [school, subject, grade] as any
  }
  formList.value[0].options = subject.data
  formList.value[1].options = teacher.data
}
const formRef = ref<any>(null)
const comfirm = async () => {
  console.log(props.param, 'param');
  const { resumeId, processId, processSort } = store.currentResume;
  const res = await formRef.value.submitForm();
  if (!res) return;
  let param: any = {}
  res.forEach(el => {
    param[el.name] = el.value
  });
  console.log(param)
  param.resumeId = resumeId
  param.processId = processId;
  param.operator = userName;
  param.result = "通过";
  param.entrySchool = param.cascader[0]
  param.entryUnit = param.cascader[1];
  param.entryPosition = param.cascader[2];
  let data: any = {}
  if (processSort == 43) {
    data = await onBoardingProgress(param);
  } else if (processSort == 39) {
    param.editStatus = "ENTRY";
    data = await secondInterview(param);
  }
  if (data && data.code === '10000') {
    message.success("操作成功");
    show.value = false
    store.getResumeInfo(resumeId)
  } else {
    message.error(data.msg)
  }
}
defineExpose({ show })
</script>

<style lang="less" scoped>
.progress {
  display: flex;
  justify-content: end;
  margin: 24px 0;
  padding-top: 24px;
  ;
  font-weight: 400;
  font-size: 14px;
  color: #333333;

  .desc {

    font-weight: 400;
    font-size: 14px;
    color: #209EE4;

  }
}
</style>
